package com.lineage.data.npc.quest;

import com.lineage.data.executor.NpcExecutor;
import com.lineage.server.model.L1Teleport;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.ServerBasePacket;

import java.util.Iterator;
import java.util.Random;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Npc_Harding extends NpcExecutor {
  private static final Log _log = LogFactory.getLog(Npc_Harding.class);
  public static final Random _random = new Random();
  public static NpcExecutor get() {
    return new Npc_Harding();
  }
  
  public int type() {
    return 3;
  }
  
  public void talk(L1PcInstance pc, L1NpcInstance npc) {
    try {
      if (pc.get_hardinR() != null)
        if (pc.get_hardinR().get_time() > 0 && pc.get_hardinR().get_time() <= 180) {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "j_ep002"));
//          action(pc, npc, "startgame", 0);
        } else {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "j_ep001"));
        }  
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  
//  public void action(L1PcInstance pc, L1NpcInstance npc, String cmd) {
  public void action(L1PcInstance pc, L1NpcInstance npc, String cmd, long amount) {
		if (cmd.equalsIgnoreCase("startgame")) {
//			Iterator<L1PcInstance> iterator = pc.getParty().partyUsers().values().iterator();
			
			
			for (Iterator<L1PcInstance> iterator = pc.getParty().partyUsers().values().iterator();iterator.hasNext();) {
				L1PcInstance member = (L1PcInstance) iterator.next();
				 L1Teleport.teleport(member, 32665 + _random.nextInt(5) - 2, 
			              32794 + _random.nextInt(5) - 2, (short)9000, 0, true);
			}
		}
	}
  
  
}
